<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="/WEB-INF/tag/c.tld"%>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>代码生成器</title>
	<%@ include file="../../include/style.jsp"%>
	<link href="${webRoot}/assets/jforest/css/jforest-tree.css" rel="stylesheet" media="screen">
	<%@ include file="../../include/js.jsp"%>
	<script type="text/javascript" src="${webRoot}/assets/jforest/js/jforest-paging.js"></script>
	<script type="text/javascript" src="${webRoot}/assets/jforest/js/jforest-table.js"></script>
	<script type="text/javascript" src="${webRoot}/assets/jforest/js/jforest-form.js"></script>
	<script type="text/javascript" src="${webRoot}/assets/jforest/js/jforest-tree.js"></script>
</head>
<body>
<div class="container">
	<ol class="breadcrumb">
	  <li><a href="${webRoot}/">项目列表</a></li>
	  <li><a href="${webRoot}/pageConfig?code=${project.projectCode}">页面配置</a></li>
	  <li class="active">菜单配置</li>
	</ol>
<div id="divConfigMenu" class="row">
	<aside class="col-lg-3">
		<section class="panel panel-default">
			<div class="panel-body" id="divMenuTree" style="min-height:700px;"></div>
		</section>
	</aside>
	<aside class="col-lg-9">
		<section class="panel panel-default">
			<div class="panel-body">
				<b>移动菜单：</b><span id="spanMoveMenuInfo"></span>
				<input type="hidden" id="inpMoveId"/>
			</div>
		</section>
		<section class="panel panel-default">
			<div class="panel-heading clearfix">
				<b id="bTableTitle">全部菜单</b>
				<input type="hidden" name="menuCode" id="inpParentMenuId"/>
				<button id="btnAddMenu" class="btn btn-success btn-sm pull-right">添加</button>
			</div>
			<div class="panel-body" style="min-height:600px;">
			<table class="table table-bordered table-hover" id="tableMenuList">
				<thead><tr>
					<th data-code="code">菜单代码</th><th data-code="name">菜单名称</th>
					<th data-code="url">菜单访问路径</th><th data-code="operate">操作</th>
				</tr></thead>
			</table>
			</div>
		</section>
	</aside>
</div>
</div><!-- /.container -->
<script type="text/javascript">
$(function(){
	$('#divMenuTree').jfTree({
		ajax:{
			url:'${webRoot}/pageConfig/menu/tree',
			param:function(node){
				return {
					pcode:'${project.projectCode}',
					pid:node.options.id
				}
			}
		},
		root:{
			id:null,
			name:'全部菜单'
		},
		nodeClick:function(node){
			var moveId = $('#inpMoveId').val();
			if(moveId){
				$('#inpMoveId').val('');
				$('#spanMoveMenuInfo').html('');
				$.getJSON('${webRoot}/pageConfig/menu/move',{
					pcode:'${project.projectCode}',
					srcId:moveId,
					targetId:node.options.id
				},function(result){
					if(result.error == 1){
						$('#tableMenuList').jfTable('loadData');
						$('#divMenuTree').jfTree('refresh');
						jf.info('移动成功');
					}else{jf.error(result.msg);}
				});
			}else{
				$('#inpParentMenuId').val(node.options.id);
				$('#bTableTitle').html(node.options.name);
				$('#tableMenuList').jfTable('loadData');
			}
		}
	});
	
	$('#tableMenuList').jfTable({
		pagingEl:null,
		ajax:{
			url:'${webRoot}/pageConfig/menu/data',
			param:function(param){
				return {
					pcode:'${project.projectCode}',
					pid:$('#inpParentMenuId').val()
				};
			}
		},
		cols:{
			operate:{
				icons:[{
					tooltip:'编辑',
					icon:'fa-edit',
					click:function(record){
						jf.modal('修改菜单','${webRoot}/pageConfig/menu/edit',{
								pcode:'${project.projectCode}',
								id:record.id},function(result){
							if(result.error==1){
								$('#divMenuTree').jfTree('refresh');
								$('#tableMenuList').jfTable('loadData');
								$(this).modal('hide');
								jf.info("修改成功");
							}else{jf.error(result.msg);}
						});
					}
				},{
					tooltip:'移动',
					icon:'fa-arrows-alt',
					click:function(record){
						$('#inpMoveId').val(record.id);
						$('#spanMoveMenuInfo').html(record.name+'-ID:'+record.id);
					}
				}]
			}
		}
	});
	
	$('#btnAddMenu').click(function(){
		jf.modal('添加菜单','${webRoot}/pageConfig/menu/edit',{
				pcode:'${project.projectCode}',
				pid:$('#inpParentMenuId').val()},function(result){
			if(result.error==1){
				$('#divMenuTree').jfTree('refresh');
				$('#tableMenuList').jfTable('loadData');
				$(this).modal('hide');
				jf.info("保存成功");
			}else{jf.error(result.msg);}
		});
	});
})
</script>
</body>
</html>